From 2d2d5805bc1120be324bd1927761197e03510719 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 29 Nov 2004 17:58:28 +0000 Subject: [PATCH] Make User::newFromName set the user object's ID attribute, so it can be used for other methods and lazy loading. Previously, you had to use the class method idForName and assign its value using setId(). Since all the code that was using newFromName was doing this, it seems like client programs want a "real" User returned from newFromName. Replaced client code that was doing newFromName, idForName, setId with just newFromName. This doesn't seem to break newFromName's semantics; it seems intuitive (to me) that the user object returned from newFromName should be usable as returned. --- includes/Article.php | 1 - includes/SpecialEmailuser.php | 5 ++--- includes/SpecialUserlevels.php | 10 ++++------ includes/SpecialUserlogin.php | 9 +++------ includes/User.php | 1 + 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 13b42efa17..ae99a953d2 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1877,7 +1877,6 @@ class Article { $shortTitle != $wgUser->getName()) { $other = User::newFromName($shortTitle); - $other->setID(User::idFromName($shortTitle)); $other->setNewtalk(1); $other->saveNewtalk(); } diff --git a/includes/SpecialEmailuser.php b/includes/SpecialEmailuser.php index 5da20d8d20..6006b25810 100644 --- a/includes/SpecialEmailuser.php +++ b/includes/SpecialEmailuser.php @@ -40,13 +40,12 @@ function wfSpecialEmailuser( $par ) { return; } $nu = User::newFromName( $nt->getText() ); - $id = $nu->idForName(); - if ( 0 == $id ) { + if ( 0 == $nu->getID() ) { $wgOut->errorpage( "noemailtitle", "noemailtext" ); return; } - $nu->setID( $id ); + $address = $nu->getEmail(); if ( ( false === strpos( $address, "@" ) ) || diff --git a/includes/SpecialUserlevels.php b/includes/SpecialUserlevels.php index 87a7abb249..78581d0eae 100644 --- a/includes/SpecialUserlevels.php +++ b/includes/SpecialUserlevels.php @@ -115,12 +115,11 @@ class UserlevelsForm extends HTMLForm { $wgOut->addHTML('

'.wfMsg('nosuchusershort',$username).'

'); return; } - $id = $u->idForName(); - if($id == 0) { + + if($u->getID() == 0) { $wgOut->addHTML('

'.wfMsg('nosuchusershort',$username).'

'); return; } - $u->setID( $id ); $groups = $u->getGroups(); $logcomment = ' '; @@ -214,12 +213,11 @@ class UserlevelsForm extends HTMLForm { $wgOut->addHTML('

'.wfMsg('nosuchusershort',$username).'

'); return; } - $id = $user->idForName(); - if($id == 0) { + + if($user->getID() == 0) { $wgOut->addHTML('

'.wfMsg('nosuchusershort',$username).'

'); return; } - $user->setID( $id ); $groups = $user->getGroups(); diff --git a/includes/SpecialUserlogin.php b/includes/SpecialUserlogin.php index 0a913cf9ab..87c004cb3b 100644 --- a/includes/SpecialUserlogin.php +++ b/includes/SpecialUserlogin.php @@ -240,8 +240,7 @@ class LoginForm { $this->mainLoginForm( wfMsg( 'noname' ) ); return; } - $id = $u->idForName(); - if ( 0 == $id ) { + if ( 0 == $u->getID() ) { global $wgAuth; /** * If the external authentication plugin allows it, @@ -257,7 +256,6 @@ class LoginForm { return; } } else { - $u->setId( $id ); $u->loadFromDatabase(); } if (!$u->checkPassword( $this->mPassword )) { @@ -302,12 +300,11 @@ class LoginForm { $this->mainLoginForm( wfMsg( 'noname' ) ); return; } - $id = $u->idForName(); - if ( 0 == $id ) { + if ( 0 == $u->getID() ) { $this->mainLoginForm( wfMsg( 'nosuchuser', $u->getName() ) ); return; } - $u->setId( $id ); + $u->loadFromDatabase(); $error = $this->mailPasswordInternal( $u ); diff --git a/includes/User.php b/includes/User.php index 07d02277df..d9aa940dde 100644 --- a/includes/User.php +++ b/includes/User.php @@ -55,6 +55,7 @@ class User { return NULL; } else { $u->setName( $t->getText() ); + $u->setId( $u->idFromName( $t->getText() ) ); return $u; } } -- 2.20.1